package com.hh.releasenode.controller;

import com.hh.releasenode.entity.SysUserEntity;
import com.hh.releasenode.utils.Constant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName AbstractController
 * @Description contooler公共组件
 * @Author KunxianLi
 * Date 2020/7/4 14:41
 * Version 1.0
 **/
@Slf4j
public abstract class AbstractController {

    /**
     * @Author KunxianLi
     * @Description 获取登陆的用户信息
     * @Date 2020/7/6 16:41
     * @Param []
     * @return com.hh.releasenode.entity.SysUserEntity
     **/
    public SysUserEntity getUser(){

        return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();

    }

    /**
     * @Author KunxianLi
     * @Description 获取请求token
     * @Date 2020/7/6 17:02
     * @Param [request]
     * @return java.lang.String
     **/
    public String getToken(HttpServletRequest request){
        String token = request.getHeader(Constant.TOKEN);
        if(StringUtils.isBlank(token)){
            token = request.getParameter(Constant.TOKEN);
        }
        if(StringUtils.isBlank(token)){
            token = (request.getAttribute(Constant.TOKEN)==null?"":request.getAttribute(Constant.TOKEN))+"";
        }
        return token;
    }


}
